﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using mborn.Model;
using mborn.BLL;

public partial class blog_UserClass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnAddUserClass_Click(object sender, EventArgs e)
    {
        string strUserClassName;
        int intUserID = 0;
        strUserClassName = tbUserClassName.Text;

        HttpCookie acookie = Request.Cookies["ID"];

        if (acookie != null)
            intUserID = Convert.ToInt32(acookie.Value);

        UserClass model = new UserClass();
        UserClassBLL bll = new UserClassBLL();

        model.ClassCnt = 0;
        model.ClassName = strUserClassName;
        model.UserID = intUserID;

        bll.AddUserClass(model);

        lblMessage.Text = "新标签添加成功";

        //刷新
        ddlRefresh();


    }


    /// <summary>
    /// 在数据库操作后整个页面的下拉列表的刷新
    /// </summary>
    protected void ddlRefresh() 
    {
        ddlUserClassDel.DataBind();
        ddlUserClassEdit.DataBind();
        ddlUserClassMerge1.DataBind();
        ddlUserClassMerge2.DataBind();
    }
    protected void btnUserClassEdit_Click(object sender, EventArgs e)
    {
        string strUserClassName;
        int intUserID = 0;
        int intID = 0;
        int intCnt = 0;

        UserClassBLL bll=new UserClassBLL ();
        UserClass model=new UserClass ();

        HttpCookie acookie=Request .Cookies["ID"];

        if (acookie != null)
            intUserID = Convert.ToInt32(acookie.Value );

        strUserClassName = tbUserClassEdit .Text ;
        intID = Convert.ToInt32(ddlUserClassEdit.SelectedValue);

        intCnt = bll.GetCntByID(intID);
        model.ID = intID;
        model.UserID = intUserID;
        model.ClassCnt = intCnt;
        model.ClassName = strUserClassName;

        bll.UpdateUserClass(model);

        lblmsgEdit.Text = ddlUserClassEdit.SelectedItem.Text + "已更新成" + strUserClassName;
        ddlRefresh();
    }
    protected void btnUserClassDel_Click(object sender, EventArgs e)
    {
        int intID = 0;

        UserClassBLL bll = new UserClassBLL();
        UserClass model = new UserClass();

        intID = Convert.ToInt32 ( ddlUserClassDel.SelectedValue);

        model.ID = intID;

        bll.DelUserClass(model);

        lblmsgDel.Text = ddlUserClassDel.SelectedItem.Text + " 已被删除";

        ddlRefresh();
    }
}
